package org.gurms.web.filter;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.gurms.common.config.GlobalMessage;
import org.gurms.common.util.SpringUtil;
import org.gurms.service.system.SysUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import freemarker.ext.beans.BeansWrapper;
import freemarker.ext.beans.ResourceBundleModel;

public class GurmsContextListener implements ServletContextListener {

	private final Logger logger = LoggerFactory.getLogger(getClass());

	public void contextDestroyed(ServletContextEvent event) {
		event.getServletContext().removeAttribute("bundle");
	}

	public void contextInitialized(ServletContextEvent event) {
		// freemark 国际化
		ResourceBundleModel rbm = new ResourceBundleModel(GlobalMessage.message, new BeansWrapper());
		event.getServletContext().setAttribute("bundle", rbm);
		logger.info("initialize freemark resource ok......");

		SysUserService userService = SpringUtil.getBean("sysUserServiceImpl");
		userService.getAll(null);
		logger.info("cache for sysparam ok......");
	}

}
